<?php

/**
 * 按照趣炫要求签名方法
 * 趣炫聊天监控封号及帮派接口
 * Game_name   : S10       (封号和帮派接口使用)
 * Game_id :   31
 * API_KEY :   IFHCBDKCM963G1VD (封号和帮派接口使用)
 * @author yuxun
 *
 */
class ChatController extends Controller {
	public function __construct($id,$module=null){
		parent::__construct();
	}

	
	public function beforeAction($action){
		$local_sign = $this->getSign();
		
		$sign = PubRequest::R('sign');

		if($local_sign != $sign){
			$json_arr = array('state'=>1,'msg'=>'check_sign_err' );
			ApiBaseService::doLog($_POST, $json_arr);
			exit(json_encode($json_arr));
		}
			
		return parent::beforeAction($action);
	}
	
	
	/**
	 * md5(key1=value1&key2=value2&key3=value3+api_key) ; 
其中“+”号只做连接作用实际上并没参与加密，各参数之间没有空格，按参数字段升序排列后，以键值对形式拼接.
（备注：sign签名需要md5加密而成）
	 * @return string
	 */
	protected function getSign(){
		header("Content-type:text/html;charset=utf-8");
		$key = Yii::app()->params['QX_CHAT_KEY'];
		$data = $_POST;

		unset($data['sign']);   
		ksort($data);
		$sign = md5($key.http_build_query($data));
		
		return $sign;
	}
    
	/**
	 * http://www.tm.com/api/?r=chat/forbid
	 * http://admin.s10.q-dazzle.com:8090/api/?r=chat/forbid
	 * forbid(封号)/mute(禁言)/army_kickout(踢出帮派)
	 * game_name S10
	 * game_id 31
	 */
	public function forbid(){
		$game_name = PubRequest::R('game_name');
		$plat_cname = PubRequest::R('plat_cname');
		$server_id = PubRequest::R('server_id');
		$plat_user_name = PubRequest::R('plat_user_name');
		$role_id = PubRequest::R('role_id');
		$forbid_time = PubRequest::R('forbid_time');
		$army_id = PubRequest::R('army_id');
		$type = PubRequest::R('type'); // forbid(封号)/mute(禁言)/army_kickout(踢出帮派)
		
		$json_arr = ChatService::forbid($game_name,$plat_cname,$server_id,$plat_user_name,$role_id,$forbid_time,$army_id,$type);
		ApiBaseService::doLog($_POST, $json_arr);
		exit(json_encode($json_arr));
	}
	
	
   

}